package dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree;

public enum CompareOperator {
    EQUAL("="), LESS_THAN("<"), LESS_THAN_OR_EQUAL("<="), GREATER_THAN(">"), GREATER_THAN_OR_EQUAL(">=");

    public static CompareOperator valueOfSymbol(String symbol) {
        for (CompareOperator compareOperator : values()) {
            if (compareOperator.getSymbol().equals(symbol)) {
                return compareOperator;
            }
        }
        throw new IllegalArgumentException("No compare operator with symbol: " + symbol);
    }


    private String symbol;

    CompareOperator(String symbol) {
        this.symbol = symbol;
    }

    public String getSymbol() {
        return symbol;
    }

    public boolean compare(int leftside, int rightside) {
        switch (this) {
            case EQUAL:
                return (leftside == rightside);
            case GREATER_THAN_OR_EQUAL:
                return (leftside >= rightside);
            case LESS_THAN_OR_EQUAL:
                return (leftside <= rightside);
            case GREATER_THAN:
                return (leftside > rightside);
            case LESS_THAN:
                return (leftside < rightside);
            default:
                throw new RuntimeException("can't compare for operator " + this.name());
        }
    }
}
